package com.mentaleye.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.DormitoryStudentBean;
import com.mentaleye.dal.dao.DormitoryStudentDao;
import com.mentaleye.dal.model.DormitoryStudent;
import com.mentaleye.dal.model.DormitoryStudentExample;
import com.mentaleye.service.DormitoryStudentService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.ObjectUtil;
@Service
public class DormitoryStudentServiceImpl implements DormitoryStudentService {
@Autowired private DormitoryStudentDao dormitoryStudentDao;
	@Override
	public boolean addDormitoryStudent(DormitoryStudentBean dormitoryStudentBean) {
		DormitoryStudent dormitory = (DormitoryStudent) ObjectUtil.transfer(dormitoryStudentBean, DormitoryStudent.class);
		return dormitoryStudentDao.insertDormitoryStudent(dormitory);
	}

	@Override
	public boolean editDormitoryStudent(DormitoryStudentBean dormitoryStudentBean) {
		DormitoryStudent dormitory = (DormitoryStudent) ObjectUtil.transfer(dormitoryStudentBean, DormitoryStudent.class);
		return dormitoryStudentDao.modifyDormitoryStudent(dormitory);
	}

	@Override
	public boolean removeDormitoryStudent(Integer stuId,Integer dorId) {
		return dormitoryStudentDao.deleteDorStudent(stuId,dorId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DormitoryStudentBean> getAllDirmitoryStudent(DormitoryStudentExample example) {
		return ObjectUtil.transferList(dormitoryStudentDao.queryAllDormitory(example), DormitoryStudentBean.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DormitoryStudentBean> getDormitoryRelateStudentById(Integer id) {
		return ObjectUtil.transferList(dormitoryStudentDao.queryDormitoryStudentById(id),DormitoryStudentBean.class);
	}

	@Override
	public int getStudentCountByDorId(Integer dorId) {
		return dormitoryStudentDao.queryStudentCountByDorId(dorId);
	}

	@Override
	public boolean isExistRelate(Integer dorId, Integer stuId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dorId", dorId);
		map.put("stuId", stuId);
		return dormitoryStudentDao.isExistRelate(map);
	}

	@Override
	public DormitoryStudentBean getDormitoryRelateStudentByStuId(Integer stuId) {
		return (DormitoryStudentBean) ObjectUtil.transfer(dormitoryStudentDao.queryDormitoryStudentByStuId(stuId),DormitoryStudentBean.class);
	}

	@Override
	public boolean removeDormitoryStudentByStatus(Integer stuId, Integer status) {
		return dormitoryStudentDao.deleteDormitoryStudent(stuId,status);
	}

	@Override
	public void getMap(CommonPage commonPage) {
		List<Map<String, Object>> data = dormitoryStudentDao.queryMap(commonPage.pageToMap());
		commonPage.setPageData(data);
	}

	@Override
	public DormitoryStudentBean getDorStudentByStuIdAndDor(Integer stuId, Integer dorId, Integer stayStatus) {
		return (DormitoryStudentBean) ObjectUtil.transfer(dormitoryStudentDao.queryDorStudentByStuIdAndDor(stuId,dorId,stayStatus),DormitoryStudentBean.class);
	}

}
